package com.itheima.exerciseTest.method40_49.method49;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

// 服务器
public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10011);
        ThreadPoolExecutor pool = new ThreadPoolExecutor(2,
                5,
                1, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());


        while (true){
            Socket accept = ss.accept();
            ThreadServer ts = new ThreadServer(accept);
            pool.submit(ts);
        }

       // ss.close();
    }
}

